package com.ruoyi.project.task.transferRatify.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.person.info.domain.PersonInfo;
import com.ruoyi.project.task.mission.service.ITaskMissionService;
import com.ruoyi.project.task.transfer.domain.TaskTransfer;
import com.ruoyi.project.task.transfer.service.ITaskTransferService;
import com.ruoyi.project.task.transferRatify.service.ITransferRatifyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Pathosis
 * @date 2020-09-20 10:25
 * @description:
 */
@Controller
@RequestMapping("task/transferRatify")
public class TransferRatifyController extends BaseController{

    private String prefix = "task/transferRatify";

    @Autowired
    private ITaskTransferService itts;

    @Autowired
    private ITaskMissionService itms;

    @Autowired
    private ITransferRatifyService itrs;

    @RequiresPermissions("task:transferRatify:view")
    @GetMapping
    public String toPostpone(){
        return prefix + "/transferRatify";
    }

    @RequiresPermissions("task:transferRatify:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaskTransfer taskTransfer)
    {
        //分页
        startPage();

        List<TaskTransfer> list = itrs.selectTaskTransferList(taskTransfer);

        return getDataTable(list);
    }

    @GetMapping("/edit/{transferId}")
    public String edit(@PathVariable("transferId") Long transferId, ModelMap mmap)
    {
        mmap.addAttribute("taskTransfer", itts.selectTaskTransferById(transferId));
        List<PersonInfo> personInfos = itms.selectAllPerson();
        mmap.addAttribute("list",personInfos );
        return prefix + "/edit";
    }


    @RequiresPermissions("task:transferRatify:edit")
    @Log(title = "任务延期管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated TaskTransfer taskTransfer) {
        System.out.println(taskTransfer);
        return toAjax(itts.updateTaskTransferByRatifyIsSuccess(taskTransfer));
    }


}
